// 禁用变量命名警告
#![allow(non_snake_case)]

mod controller;
mod pojo;
mod utils;

use actix_web::{App, HttpServer, web, guard, HttpResponse};

use std::collections::HashMap;
use std::path::PathBuf;

include!(concat!(env!("OUT_DIR"), "/generated.rs"));

// 设置静态变量
#[macro_use]
extern crate lazy_static;
lazy_static! {
    pub static ref SHARED_PATH: PathBuf = PathBuf::from(r"C:\Users\Administrator.W10-20201229857\Desktop");
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    let app = HttpServer::new(|| {
        let generated = generate();
        App::new()
            .service(controller::index)
            .service(controller::files)
            .service(controller::shared)
            .service(controller::newDir)
            .service(controller::test1)
            .service(controller::test2)
            .default_service(web::route()
                                 .guard(guard::Not(guard::Get()))
                                 .to(|| HttpResponse::MethodNotAllowed()), )
            // 静态文件
            .service(actix_web_static_files::ResourceFiles::new("/", generated))
    })
        .bind("0.0.0.0:8080")?
        .run();
    println!("服务器在 http://127.0.0.1:8080 启动成功");
    return app.await;
}
